package com.slmxz.tms.document.controller;

import com.slmxz.tms.common.model.Query;
import com.slmxz.tms.common.result.PageResult;
import com.slmxz.tms.common.result.Result;
import com.slmxz.tms.common.support.Condition;
import com.slmxz.tms.document.model.entity.SettleCurrency;
import com.slmxz.tms.document.model.vo.SettleCurrencyVO;
import com.slmxz.tms.document.service.SettleCurrencyService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;

/**
 * 结算币种汇率前端控制层
 * @author sunyao
 * @Date 2024-11-15
 */
@Tag(name = "结算币种汇率接口")
@RestController
@RequestMapping("/document/settleCurrency")
@RequiredArgsConstructor
public class SettleCurrencyController  {

    private final SettleCurrencyService settleCurrencyService;

    @Operation(summary = "结算币种汇率分页列表")
    @GetMapping("/page")
    public PageResult<SettleCurrencyVO> selectSettleCurrencyPage(Query query, SettleCurrencyVO settleCurrency) {
        IPage<SettleCurrencyVO> result = this.settleCurrencyService
                .selectSettleCurrencyPage(Condition.getPage(query),settleCurrency);
        return PageResult.success(result);
    }

    @Operation(summary = "新增结算币种汇率")
    @PostMapping("/save")
    @PreAuthorize("@ss.hasPerm('document:settleCurrency:add')")
    public Result<Void> saveSettleCurrency(@RequestBody @Valid SettleCurrencyVO  settleCurrency) {
        boolean result = this.settleCurrencyService.saveSettleCurrency(settleCurrency);
        return Result.result(result);
    }

    @Operation(summary = "获取结算币种汇率详情数据")
    @GetMapping("/detail/{id}")
    @PreAuthorize("@ss.hasPerm('document:settleCurrency:edit')")
    public Result<SettleCurrency> selectSettleCurrencyDetail(
        @Parameter(description = "结算币种汇率ID") @PathVariable Long id
    ) {
        SettleCurrency settleCurrency = this.settleCurrencyService.selectSettleCurrencyDetail(id);
        return Result.success(settleCurrency);
    }

    @Operation(summary = "修改结算币种汇率")
    @PutMapping(value = "/update")
    @PreAuthorize("@ss.hasPerm('document:settleCurrency:edit')")
    public Result<Void> updateSettleCurrency(
            @RequestBody @Validated SettleCurrency settleCurrency
    ) {
        boolean result = settleCurrencyService.updateSettleCurrency(settleCurrency);
        return Result.result(result);
    }

    @Operation(summary = "删除结算币种汇率")
    @DeleteMapping("/remove/{ids}")
    @PreAuthorize("@ss.hasPerm('document:settleCurrency:delete')")
    public Result<Void> deleteSettleCurrencys(
        @Parameter(description = "结算币种汇率ID，多个以英文逗号(,)分割") @PathVariable String ids
    ) {
        boolean result = this.settleCurrencyService.deleteSettleCurrencys(ids);
        return Result.result(result);
    }

    @Operation(summary = "激活或者注销结算币种汇率")
    @PostMapping("/activeOrLogout")
    @PreAuthorize("@ss.hasPerm('document:business:delete')")
    public Result<Void> activeOrLogout(@RequestBody SettleCurrencyVO settleCurrency) {
        boolean result = this.settleCurrencyService.activeOrLogout(settleCurrency);
        return Result.result(result);
    }
}
